package com.jy.appmarket.screenlock.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.jy.appmarket.AppMarketApplication;
import com.jy.appmarket.screenlock.LockScreenManager;

/**
 * 类说明：
 * 
 * @author kalui.huang
 * @date 2015-3-20
 * @version 1.0
 */
public class KeyEventReceiver extends BroadcastReceiver {
	String SYSTEM_REASON = "reason";
	String SYSTEM_HOME_KEY = "homekey";
	String SYSTEM_HOME_KEY_LONG = "recentapps";

	@Override
	public void onReceive(Context context, Intent intent) {
		String action = intent.getAction();
		if (!action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
			return;
		}
		String reason = intent.getStringExtra(SYSTEM_REASON);
		if (TextUtils.equals(reason, SYSTEM_HOME_KEY)
				|| TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)) {
			if (LockScreenManager.getInstance(context).isShowMode()) {
				LockScreenManager.getInstance(context).unLock(true);
				return;
			}

			if (AppMarketApplication.sIsPauseLocked) {
				LockScreenManager.getInstance(context).lock();
			}
		}
	}
}
